<?php

namespace app\admin\controller;

use \app\common\model\Yuyue as YuyueModel;
use app\common\model\YuyueFankui;

class Yuyue extends Base
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 分页获取预约信息
     * @return void
     */
    public function list()
    {
        //查询条件
        $where = array();

        if(input('mid')){
            $where['mid'] = array('eq',input('mid'));
        }

        //分页信息
        $page = max(input('page'), 1);
        $size = 20;
        //获取分页列表
        $list = YuyueModel::getPage($where, $page, $size, 'id desc');
        //总页码
        $total = YuyueModel::getCount($where);
        //数据返回
        if (!$list) {
            return returnJson(1, '');
        }
        return returnJson(0, '', [
            'list' => $list,
            'size' => $size,
            'total' => $total
        ]);
    }

    /**
     * 根据条件获取信息
     * @return \think\response\Json
     */
    public function index(){
        //查询条件
        $where = [
            'id' => input('id')
        ];
        //信息
         $yuyue= YuyueModel::getOne($where);

        //返回信息
        return returnJson(0,'success',$yuyue);
    }

    public function fankui(){
        $save = input('');
        if(request()->isPost()){
            $time = time();
            $save['update_time'] = $time;
            $save['create_time'] = $time;
            YuyueFankui::setInsertGetId($save);
            YuyueModel::setIncr(['id'=>['eq',$save['wid']]],'status');

            return returnJson(0, '操作成功');
        }
        return returnJson(1, '网络异常，请重试');
    }

    /**
     * 给预约学员分配教练
     * @return \think\response\Json
     */
    public function updateCoach()
    {
        if(request()->isPost()){
            //条件
            $where = array(
                'id' => array('eq',input('id'))
            );

            //更新后的数据
            $time = time();
            $save['update_time'] = $time;
            $save['mid'] = input('mid');
            $save['manager_name'] = input('manager_name');
            YuyueModel::update($save,$where);

            return returnJson(0, '操作成功');
        }
        return returnJson(1, '网络异常，请重试');


    }


}
